package com.ydkfjs.controller;

import com.ydkfjs.common.Result;
import com.ydkfjs.model.dto.ItemRequest;
import com.ydkfjs.model.po.Item;
import com.ydkfjs.model.vo.ItemVO;
import com.ydkfjs.service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: hb
 * @CreateTime: 2024-04-22 18:55
 * @Version: 1.0
 */
@Api(tags = "物品模块")
@RestController
@RequestMapping("/item")
@Slf4j
public class ItemController {

    private final ItemService itemService;

    public ItemController(ItemService itemService) {
        this.itemService = itemService;
    }

    @ApiOperation(value = "新增物品")
    @PostMapping("/add")
    public Result<?> add(@RequestBody ItemRequest itemRequest) {
        itemService.add(itemRequest);
        return Result.success("新增成功");
    }

    @ApiOperation(value = "根据类别获取物品集合")
    @PostMapping("/getByKind")
    public Result<?> getByKind(
            @RequestParam @ApiParam(name = "kind", value = "1食物 2运动") Integer kind,
            @RequestParam @ApiParam(name = "type", value = "物品分类") Integer type) {
        List<ItemVO> list = itemService.getList(kind, type);
        return Result.success("获取成功", list);
    }

    @ApiOperation(value = "删除")
    @PostMapping("/deleteById")
    public Result<?> delete(@RequestParam Long id) {
        itemService.deleteById(id);
        return Result.success("删除成功");
    }
}
